#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,m,L,V,over,ans;
struct car{
    ll d,v,a,early,late;
}C[100050];
vector<ll> pst[100050],ped[100050];
bool detectable[100050];//ok
bool ifdet[100050];
ll P[100050];//ok
vector<ll> In;
bool check(ll d,ll v,ll a,ll tar){
    if(tar<d) return false;
    return v*v+2*a*(tar-d)>V*V;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        memset(C,0,sizeof(C));
        memset(detectable,0,sizeof(detectable));
        memset(ifdet,0,sizeof(ifdet));
        memset(P,0,sizeof(P));
        In.clear();
        for(int i = 1;i<=100005;i++){
            pst[i].clear();
            ped[i].clear();
        }
        scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
        over = 0;
        ans = m;
        for(int i = 1;i<=n;i++){
            scanf("%lld%lld%lld",&C[i].d,&C[i].v,&C[i].a);
        }
        for(int i = 1;i<=m;i++) scanf("%lld",&P[i]);
        for(int i = 1;i<=n;i++){
            ll dis;
            if(C[i].a!=0) dis = (V*V-C[i].v*C[i].v)/(2*C[i].a);
            else dis = 0x3f3f3f3f3f3f3f3f;
            while(C[i].a>0&&C[i].v<V&&dis>=0&&!check(C[i].d,C[i].v,C[i].a,C[i].d+dis)) dis++;
            while(C[i].a<0&&C[i].v>V&&dis>=0&&!check(C[i].d,C[i].v,C[i].a,C[i].d+dis)) dis--;
            if(dis<0&&C[i].a>0) dis=-1;
            if(C[i].a>0){
                ll ind = upper_bound(P+1,P+m+1,C[i].d+dis)-P;
                //printf("%lld %lld %lld\n",C[i].d,C[i].d+dis,ind);
                if(ind>=2&&check(C[i].d,C[i].v,C[i].a,P[ind-1])){
                    C[i].early=ind-1;
                    C[i].late = m;
                    detectable[i] = 1;
                }
                else if(ind<=m&&check(C[i].d,C[i].v,C[i].a,P[ind])){
                    C[i].early=ind;
                    C[i].late = m;
                    detectable[i] = 1;
                }
            }
            else{
                if(C[i].a<=0&&C[i].v<=V) continue;
                ll ind1 = lower_bound(P+1,P+m+1,C[i].d+dis)-P-1;
                ll ind2 = lower_bound(P+1,P+m+1,C[i].d)-P;
                //printf("%lld %lld %lld\n",C[i].d,C[i].d+dis,ind1);
                if(ind1<=m-1&&check(C[i].d,C[i].v,C[i].a,P[ind1+1])){
                    C[i].early = max(ind2,1LL);
                    C[i].late = ind1+1;
                    if(C[i].early<=C[i].late) detectable[i] = 1;
                }
                else if(ind1>=1&&check(C[i].d,C[i].v,C[i].a,P[ind1])){
                    C[i].early = max(ind2,1LL);
                    C[i].late = ind1;
                    if(C[i].early<=C[i].late) detectable[i] = 1;
                }
            }
        }
        //for(int i = 1;i<=n;i++) printf("%lld %lld\n",C[i].early,C[i].late);
        for(int i = 1;i<=n;i++){
            if(detectable[i]) over++;
            /*else if(T==1){
                ll dis;
                if(C[i].a!=0) dis = (V*V-C[i].v*C[i].v)/(2*C[i].a);
                else dis = 0x3f3f3f3f3f3f3f3f;
                if(dis<0) dis=-1;
                printf("%lld %lld %lld %lld ",n,m,L,V);
                printf("%lld %lld %lld ",C[i].d,C[i].v,C[i].a);
                printf("%lld %lld ",C[i].early,C[i].late);
                printf("%d ",upper_bound(P+1,P+m+1,C[i].d+dis)-P);
                printf("%lld %lld\n",P[m-1],P[m]);
            }*/
        }
        printf("%lld ",over);
        for(int i = 1;i<=n;i++){
            if(!detectable[i]) continue;
            ll e = C[i].early, l = C[i].late;
            pst[e].push_back(i);
            ped[l].push_back(i);
        }
        /*for(int i = 1;i<=m;i++){
            printf("%lld\n",i);
            for(auto j:pst[i]) printf("%lld ",j);
            printf("\n");
            for(auto j:ped[i]) printf("%lld ",j);
            printf("\n");
        }*/
        for(int i = 1;i<=m;i++){
            for(int j = 0;j<pst[i].size();j++) if(!ifdet[pst[i][j]]) In.push_back(pst[i][j]);
            if(ped[i].size()){
                ll flag = 0;
                for(int j = 0;j<ped[i].size();j++){
                    if(!ifdet[ped[i][j]]){
                        flag = 1;
                        break;
                    }
                }
                if(!flag) continue;
                //printf("%lld! ",i);
                ans--;
                for(int j = 0;j<In.size();j++) ifdet[In[j]]=1;
                In.clear();
            }
        }
        //printf("\n");
        printf("%lld\n",ans);
    }
    return 0;
}
/*
ll T,n,m,L,V,over;
struct car{
    ll d,v,a,early,late;
}C[100050];
vector<ll> pst[100050],ped[100050];
bool ifdet[100050];
*/
